<?php

/**
 * Contadores
 * 
 * @package Sgit 
 * @author Juan Manuel Martinez Carrillo
 * @copyright Juan Manuel Martinez Carrillo
 * @version 2012
 * @access public
 * @revision 17/02/2012 9:06:
 * 
 */



class ContadoresController extends Sgit_Controller_Action
{
    
    protected $_main_model = 'Contadores';
    protected $_main_form = 'Contadores';
    protected $_checkZona = TRUE;
    

    function indexAction()
    {
        $this->setParam('activo',1);
        
        $proyectos =    new Sgit_Form_Element_Select_Proyectos('id_proyecto');
        $salas =        new Sgit_Form_Element_Select_Salas('id_sala');
        $cc =           new Sgit_Form_Element_Select_CC('id_cc');
        $tipos =        new Sgit_Form_Element_Select_Xml('ContadorTipo');
        $activo =       new Sgit_Form_Element_Select_SiNo('activo');
        $activo->setLabel('Activo');
        $activo->setValue($this->_getParam('activo'));
        
        $filtros = new Sgit_Form_Filtros();
        
        $filtros->addFormSelect($proyectos)
        ->addFormSelect($salas)
        ->addFormSelect($cc)
        ->addFormSelect($tipos)
        ->addFormSelect($activo)
        ->addExcel()
        ->addpdf()
        ->myRender();
        
        $values = $this->_getFiltrosValues($filtros);
        $values['id_zona']=$this->_idZona;
        
        
        if ($this->_request->isPost())
            $this->view->rows=$this->_model->default->getContadores($values);
        else 
            $this->view->msgPost=1;

        $this->_pdfSubTitle = $this->zona;
        $this->_export($this->view->rows);
        
        $xml = $this->_getXml($this->_actionName);

            
    }
    
    
    function tooltipAction()
    {
        $this->_helper->layout->disableLayout();
        $id= $this->_getParam('id');
        $this->view->row=$this->_model->default->getContadores($id);
    }
    
    function checkboxAction()
    {

        $checked = $this->_getParam('checked');
        $id      = $this->_getParam('id');
        
        $data['activo']=($checked=='true') ? 1 : 0;
        
        if($this->_model->default->updateRow($data,$id))
        {
            $json['status']=1;
        }else{
            $json['status']=0;
        }
        
        $this->_helper->json($json);
        
    }
    
    public function insertarAction()
    {
        $this->_insertar();
    }

    public function editarAction()
    {
        $this->_editar();
    }

    public function borrarAction()
    {
        $this->_borrar();
    }
    
    
    protected function _prepareValuesToForm($row)
    {
        $row['f_alta']=Sgit_Filter_DateDbToForm::filter($row['f_alta']);
        return $row;
    }
    
    protected function _prepareValuesToDb()
    {
        
        $row=$this->_form->getValues();
        $row['f_alta'] = Sgit_Filter_DateToDb::filter($row['f_alta']);
        
        $row['id_zona'] =$this->_idZona;
        return $row;
    }
    
    
    
    
    protected function _getFila($id)
    {
        $row = $this->_model->default->getContadores($id);
        return $row;
    }


}
